package com.yamed.customer.web;

import com.yamed.customer.client.OrderClient;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.context.request.ServletWebRequest;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.Enumeration;
import java.util.Iterator;

/**
 * @Author: wchen
 * @Description:
 * @Date: Created in 2019-08-28 14:27
 * Copyright 本内容仅限于杭州阿拉丁信息科技股份有限公司内部传阅，禁止外泄以及用于其他的商业目的
 */
@RestController
@RequestMapping("/customer/")
public class CustomerController {
    private final Logger logger = LoggerFactory.getLogger(this.getClass());

    @Resource
    private OrderClient orderClient;
    @Resource
    private HttpServletRequest servletRequest;

    @GetMapping("{userId}")
    public Integer getAllOrders(@PathVariable Long userId){
        Enumeration<String> headerNames = servletRequest.getHeaderNames();

        while (headerNames.hasMoreElements()){
            String headerName = headerNames.nextElement();
            logger.info("header:" + headerName + ":" + servletRequest.getHeader(headerName));
        }
        logger.info("getAllOrders start..." + servletRequest.getHeaderNames());
        return orderClient.countAllOrders(userId);
    }
}
